/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lanSimulation.internals;

import lanSimulation.LogManager;

/**
 *
 * @author farooq
 */
public class PSDocument extends Document {

    public PSDocument(String text){
        super(text);
    }

    public void print(LogManager logManager){
        String author = "Unknown";
        String title = "Untitled";
        int startPos = 0, endPos = 0;


        if (text.startsWith("!PS")) {
                startPos = text.indexOf("author:");
                if (startPos >= 0) {
                        endPos = text.indexOf(".", startPos + 7);
                        if (endPos < 0) {
                                endPos = text.length();
                        }

                        author = text.substring(startPos + 7,
                                        endPos);
                }

                startPos = text.indexOf("title:");
                if (startPos >= 0) {
                        endPos = text.indexOf(".", startPos + 6);
                        if (endPos < 0) {
                                endPos = text.length();
                        }

                        title = text.substring(startPos + 6,
                                        endPos);
                }

                logManager.log("\tAccounting -- author = '" + author);
                logManager.log("' -- title = '" + title + "'\n");
                logManager.log(">>> Postscript job delivered.\n\n");
                logManager.flush();
        } 
    }

}
